﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ESF.DMS.Entities.Search;
using System.Xml;
using ESF.General;
using ESF.General.Entity;
using ESF.DMS.Entities;
using ESF.FileProcessing.Entity;

#endregion


namespace ESF.DMS.DataAccess.Search
{
	public static class AdoFileReferenceSearchResult
	{
		#region Read

		public static string QueryFileReferencesByWordContents(PaggingInfo pPageInfo, FileReference pFilter, params string[] pWords)
		{
			IDbCommand cmd;
			
			
			cmd = DBContext.R.CreateSPCommand("esf_files.P_QueryFileReferencesByWordContents");

			DBContext.R.AddParameter(cmd, "pURL", pFilter.URL, General.Text.ComparisonTypes.LikeFull);
			DBContext.R.AddParameter(cmd, "pLastUpdateAction", pFilter.LastUpdateAction, General.Text.ComparisonTypes.LikeFull);
			DBContext.R.AddParameter(cmd, "pIsEnabled", pFilter.IsEnabled, General.Text.ComparisonTypes.LikeFull);
			DBContext.R.AddIDParameter(cmd, "pMonitoredDirectorySubCategoryID", pFilter.MonitoredDirectorySubCategory);
			DBContext.R.AddIDParameter(cmd, "pFileTypeID", pFilter.FileType);
			DBContext.R.AddIDParameter(cmd, "pMonitoredDirectoryID", pFilter.MonitoredDirectory);
			DBContext.R.AddDateParameter(cmd, "pCreationDate", pFilter.CreationDateTime);
			DBContext.R.AddParameter(cmd, "pCreationDateTimeStart", pFilter.filCreationDateTimeStart);
			DBContext.R.AddParameter(cmd, "pCreationDateTimeEnd", pFilter.filCreationDateTimeEnd);
			DBContext.R.AddDateParameter(cmd, "pLastWriteDate", pFilter.LastWriteDateTime);
			DBContext.R.AddParameter(cmd, "pLastWriteDateTimeStart", pFilter.filLastWriteDateTimeStart);
			DBContext.R.AddParameter(cmd, "pLastWriteDateTimeEnd", pFilter.filLastWriteDateTimeEnd);
			DBContext.R.AddParameter(cmd, "pOnlyName", pFilter.OnlyName, General.Text.ComparisonTypes.LikeFull);

			DBContext.R.AddListParameter(cmd, "pMultiOnlyName", pFilter.filMultiOnlyName, General.Text.ComparisonTypes.LikeFull);

			DBContext.R.AddParameter(cmd, "pXMLMultiLevelsSearch", AdoFileReferenceLevel.GetFilterXML (pFilter.Levels));

			DBContext.R.AddParameter(cmd, "pWordList", String.Join(",", pWords));
			
			DBContext.R.AddParameter(cmd, "pEnterpriseIdentificationNumber", pFilter.Enterprise.IdentificationNumber, General.Text.ComparisonTypes.LikeFull);
			DBContext.R.AddParameter(cmd, "pEnterpriseName", pFilter.Enterprise.Name, General.Text.ComparisonTypes.LikeFull);

			DBContext.R.AddParametersPagging(cmd, pPageInfo);


			return DBContext.R.GetMSSQLXML (cmd);
		}

		#endregion
	}
}
